home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWGDev.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  33.2 KB  |  1,273 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGDev.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #if defined(FW_PROFILER_CALLS) && defined(__MWERKS__)
  13. #pragma profile on
  14. #endif
  15.  
  16. #ifndef FWGDEV_H
  17. #include "FWGDev.h"
  18. #endif
  19.  
  20. #ifndef FWREGION_H
  21. #include "FWRegion.h"
  22. #endif
  23.  
  24. #ifndef FWPAT_H
  25. #include "FWPat.h"
  26. #endif
  27.  
  28. #ifndef FWGRGLOB_H
  29. #include "FWGrGlob.h"
  30. #endif
  31.  
  32. #ifndef FWINK_H
  33. #include "FWInk.h"
  34. #endif
  35.  
  36. #ifndef FWSTYLE_H
  37. #include "FWStyle.h"
  38. #endif
  39.  
  40. #ifndef FWFONT_H
  41. #include "FWFont.h"
  42. #endif
  43.  
  44. #ifndef FWGC_H
  45. #include "FWGC.h"
  46. #endif
  47.  
  48. #ifndef FWGRUTIL_H
  49. #include "FWGrUtil.h"
  50. #endif
  51.  
  52. #ifndef FWODGEOM_H
  53. #include "FWODGeom.h"
  54. #endif
  55.  
  56. // ----- Platform Includes -----
  57.  
  58. #if defined(FW_BUILD_MAC) && !defined(__LOWMEM__)
  59. #include <LowMem.h>
  60. #endif
  61.  
  62. #if defined(FW_BUILD_MAC) && !defined(__PRINTING_)
  63. #include <Printing.h>
  64. #endif
  65.  
  66. #ifdef FW_BUILD_MAC
  67. #include <stdio.h>    // Need sprintf for PostScript clipping
  68. #endif
  69.  
  70. // ----- OpenDoc Includes -----
  71.  
  72. #ifndef SOM_ODCanvas_xh
  73. #include <Canvas.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODTransform_xh
  77. #include <Trnsform.xh>
  78. #endif
  79.  
  80. // ----- Standard C Includes -----
  81.  
  82. #include <math.h>
  83.  
  84. //========================================================================================
  85. //    RunTime Info
  86. //========================================================================================
  87.  
  88. #if FW_LIB_EXPORT_PRAGMAS
  89. #pragma lib_export on
  90. #endif
  91.  
  92. #pragma segment FWGraphics_Device
  93.  
  94. //========================================================================================
  95. // Macros
  96. //========================================================================================
  97.  
  98. #ifdef FW_BUILD_WIN
  99.  
  100. #define FW_CHECK_PLATFORM_CANVAS \
  101.     FW_ASSERT(fPlatformCanvas != NULL);
  102.  
  103. #endif
  104.  
  105. #ifdef FW_BUILD_MAC
  106.  
  107. #define FW_CHECK_PLATFORM_CANVAS \
  108.     FW_ASSERT(fPlatformCanvas != NULL); \
  109.     FW_ASSERT(fPlatformCanvas == FW_QDGlobals.thePort);
  110.  
  111. #endif
  112.  
  113. //========================================================================================
  114. //    class FW_CGraphicDevice
  115. //========================================================================================
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    FW_CGraphicDevice::FW_CGraphicDevice
  119. //----------------------------------------------------------------------------------------
  120.  
  121. FW_CGraphicDevice::FW_CGraphicDevice(Environment *ev, ODCanvas* odCanvas) :
  122.     FW_MRefCount(),
  123.     fODCanvas(odCanvas),
  124.     fPlatformCanvas(NULL),
  125. #ifdef FW_BUILD_MAC
  126.     fPattern(FW_kBlackPat),
  127. #endif
  128.     fOpenDeviceCount(0),
  129.     fSuspended(FALSE),
  130.     fContext(NULL),
  131.     fResolution(FW_kZeroPoint),
  132.     fEV(ev)
  133. {
  134.     FW_ASSERT(fODCanvas != NULL);
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_CGraphicDevice::FW_CGraphicDevice
  139. //----------------------------------------------------------------------------------------
  140.  
  141. FW_CGraphicDevice::FW_CGraphicDevice(Environment *ev, ODPlatformCanvas platformCanvas) :
  142.     FW_MRefCount(),
  143.     fODCanvas(NULL),
  144.     fPlatformCanvas(platformCanvas),
  145. #ifdef FW_BUILD_MAC
  146.     fPattern(FW_kBlackPat),
  147. #endif
  148.     fOpenDeviceCount(0),
  149.     fSuspended(FALSE),
  150.     fContext(NULL),
  151.     fResolution(FW_kZeroPoint),
  152.     fEV(ev)
  153. {
  154.     FW_ASSERT(fPlatformCanvas != NULL);
  155. }
  156.  
  157. //---------------------------------------------------------------------------------------
  158. //     FW_CGraphicDevice::~FW_CGraphicDevice
  159. //---------------------------------------------------------------------------------------
  160.  
  161. FW_CGraphicDevice::~FW_CGraphicDevice()
  162. {
  163.     FW_ASSERT(fOpenDeviceCount == 0);
  164.     FW_ASSERT(!fSuspended);
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. //    FW_CGraphicDevice::GetResolution
  169. //----------------------------------------------------------------------------------------
  170. FW_CPoint FW_CGraphicDevice::GetResolution(Environment *ev) const
  171. {
  172.     if (fResolution == FW_kZeroPoint)
  173.     {
  174.         FW_ASSERT(fPlatformCanvas != NULL);
  175.         
  176.         FW_CGraphicDevice* self = (FW_CGraphicDevice *) this;
  177.  
  178. #ifdef FW_BUILD_WIN
  179.         self->fResolution.x = FW_IntToFixed(::GetDeviceCaps(fPlatformCanvas, LOGPIXELSX));
  180.         self->fResolution.y = FW_IntToFixed(::GetDeviceCaps(fPlatformCanvas, LOGPIXELSY));
  181. #endif
  182. #ifdef FW_BUILD_MAC
  183.         self->fResolution.x = FW_IntToFixed(72);
  184.         self->fResolution.y = FW_IntToFixed(72);
  185. #endif
  186.     }
  187.  
  188.     return fResolution;
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------
  192. //    FW_CGraphicDevice::SetResolution
  193. //----------------------------------------------------------------------------------------
  194.  
  195. void FW_CGraphicDevice::SetResolution(const FW_CPoint& resolution)
  196. {
  197.     fResolution = resolution;
  198. }
  199.  
  200. #ifdef FW_BUILD_WIN
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CGraphicDevice::IsMetaFileCanvas
  203. //----------------------------------------------------------------------------------------
  204.  
  205. FW_Boolean FW_CGraphicDevice::IsMetaFileCanvas() const
  206. {
  207.     FW_ASSERT(fPlatformCanvas);
  208.     return ::GetDeviceCaps(fPlatformCanvas, TECHNOLOGY) == DT_METAFILE;
  209. }
  210. #endif
  211.  
  212. //---------------------------------------------------------------------------------------
  213. //    FW_CGraphicDevice::OpenDevice
  214. //---------------------------------------------------------------------------------------
  215.  
  216. FW_SDeviceState* FW_CGraphicDevice::OpenDevice(Environment *ev, FW_CGraphicContext* context)
  217. {
  218. // [KVV]    FW_ASSERT(!fSuspended);
  219.  
  220.     FW_ASSERT(fContext == NULL);
  221.     fContext = context;
  222.  
  223.     // ----- Get the platform canvas -----
  224.     if (fPlatformCanvas == NULL)
  225.     {
  226. #ifdef FW_BUILD_WIN
  227.         fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODWindows);    
  228. #endif
  229. #ifdef FW_BUILD_MAC
  230.         fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODQuickDraw);    
  231. #endif
  232.     }        
  233.     FW_ASSERT(fPlatformCanvas != NULL);
  234.  
  235.     // ----- Save first the current state -----
  236.     FW_SDeviceState* deviceState = GetState();        // GetState set the port
  237.  
  238.     // ----- Reset Settings -----
  239.     if (fOpenDeviceCount == 0)
  240.     {
  241.         // Update the resolution
  242.         FW_CPoint res = GetResolution(ev);
  243.         
  244. #ifdef FW_BUILD_WIN
  245.         fTextColor = ::GetTextColor(fPlatformCanvas);
  246.         fBkColor = ::GetBkColor(fPlatformCanvas);
  247.         fPenSize.Set(0, 0);
  248.         
  249.         ::SetMapMode(fPlatformCanvas, MM_TEXT);
  250. #endif
  251. #ifdef FW_BUILD_MAC
  252.         ResetSettings();
  253.         fMacPostScriptClip = FALSE;
  254. #endif
  255.     }
  256.     
  257.     fSuspended = FALSE;        // we are opening it so it is not suspended
  258.     fOpenDeviceCount++;
  259.  
  260.     // ----- Set the origin offset -----
  261.     UpdateOriginForContext();
  262.  
  263.     return deviceState;
  264. }
  265.  
  266. //---------------------------------------------------------------------------------------
  267. //    FW_CGraphicDevice::CloseDevice
  268. //---------------------------------------------------------------------------------------
  269.  
  270. void FW_CGraphicDevice::CloseDevice(Environment *ev, FW_SDeviceState* deviceState)
  271. {
  272.     FW_CHECK_PLATFORM_CANVAS
  273.  
  274.     FW_ASSERT(!fSuspended);
  275.     FW_ASSERT(fOpenDeviceCount != 0);
  276.  
  277. #ifdef FW_BUILD_MAC
  278. // ----- [HLX] OpenDoc Bug 
  279.     // I should not have to restore the Grafport but
  280.     // ODFacet::DrawActiveBorder doesn't reset the foreground
  281.     // and background color correctly so....
  282.     ::PenNormal();
  283.     ::RGBForeColor(&FW_kRGBBlack);
  284.     ::RGBBackColor(&FW_kRGBWhite);
  285. // ----- [HLX] OpenDoc Bug
  286. #endif
  287.  
  288.     // ----- Restore origin and clip -----
  289. #ifdef FW_BUILD_WIN
  290.     ::SetWindowOrgEx(fPlatformCanvas, deviceState->fWindOrg.x, deviceState->fWindOrg.y, NULL);
  291.     ::SetMapMode(fPlatformCanvas, deviceState->fMapMode);
  292. #endif
  293. #ifdef FW_BUILD_MAC
  294.     if (fMacPostScriptClip)
  295.         MacEndPostScriptClip();
  296.  
  297.     ::SetOrigin(deviceState->fOrigin.h, deviceState->fOrigin.v);
  298.  
  299.     if (FW_MacIsColorPort(FW_QDGlobals.thePort))    // [LW7]
  300.     {
  301.         ::SetClip(deviceState->fClip);
  302.     }
  303.  
  304.     ::DisposeRgn(deviceState->fClip);
  305.     deviceState->fClip = NULL;
  306.  
  307.     // ----- Restore previous port -----
  308.     ::SetPort(deviceState->fPreviousPlatformCanvas);
  309. #endif
  310.  
  311. #ifdef FW_BUILD_MAC
  312.     // ----- Restore the suspended flag
  313.     // [KVV] CloseDevice should set fSuspended to FALSE!
  314.     fSuspended = deviceState->fSuspended;
  315. #endif
  316.  
  317.     // ----- Decrement fOpenDeviceCount -----
  318.     fOpenDeviceCount--;
  319.     
  320.     // ----- If fOpenDeviceCount == 0 the device is not used anymore.
  321.     if (fOpenDeviceCount == 0)
  322.     {    
  323. #ifdef FW_BUILD_WIN
  324.         // ----- Unselect our object -----
  325.         fGDIPen.UnselectObject(fPlatformCanvas);
  326.         fGDIBrush.UnselectObject(fPlatformCanvas);
  327.         fGDIFont.UnselectObject(fPlatformCanvas);
  328.         
  329.         // ----- Reset also textColor, bkColor etc to their default value -----
  330.         ::SetTextColor(fPlatformCanvas, FW_kRGBBlack);
  331.         ::SetBkColor(fPlatformCanvas, FW_kRGBWhite);
  332.         ::SetROP2(fPlatformCanvas, R2_COPYPEN);
  333.         ::SetBkMode(fPlatformCanvas, OPAQUE);
  334. #endif
  335.  
  336.         if (fODCanvas != NULL)
  337.         {
  338. #ifdef FW_BUILD_WIN
  339.             fODCanvas->ReleasePlatformCanvas(ev);
  340. #endif
  341.         }
  342.         
  343.         fPlatformCanvas = NULL;
  344.     }
  345.  
  346.     // ----- We don't need the deviceState anymore -----
  347.     delete deviceState;
  348.  
  349.     // ----- Not valid anymore -----
  350.     fContext = NULL;
  351. }
  352.  
  353. //---------------------------------------------------------------------------------------
  354. //    FW_CGraphicDevice::GetState
  355. //---------------------------------------------------------------------------------------
  356.  
  357. FW_SDeviceState* FW_CGraphicDevice::GetState()
  358. {
  359.     FW_ASSERT(fPlatformCanvas != NULL);
  360.     FW_SDeviceState* deviceState = new FW_SDeviceState();
  361.     
  362. #ifdef FW_BUILD_WIN
  363.     deviceState->fMapMode = ::GetMapMode(fPlatformCanvas);
  364.     ::GetWindowOrgEx(fPlatformCanvas, &deviceState->fWindOrg);
  365. #endif
  366. #ifdef FW_BUILD_MAC
  367.     // ----- Save previous grafport -----
  368.     ::GetPort(&deviceState->fPreviousPlatformCanvas);
  369.     FW_ASSERT(deviceState->fPreviousPlatformCanvas != NULL);
  370.     
  371.     // ----- Set the new grafport -----
  372.     ::SetPort(fPlatformCanvas);
  373.     
  374.     // ----- Save the origin and the clip of our port     
  375.     deviceState->fOrigin.h = fPlatformCanvas->portRect.left;
  376.     deviceState->fOrigin.v = fPlatformCanvas->portRect.top;
  377.  
  378.     deviceState->fClip = ::FW_CopyRegion(fPlatformCanvas->clipRgn);
  379.  
  380.     deviceState->fSuspended = fSuspended;
  381. #endif
  382.  
  383.     return deviceState;
  384. }
  385.  
  386. //---------------------------------------------------------------------------------------
  387. //    FW_CGraphicDevice::Suspend
  388. //---------------------------------------------------------------------------------------
  389.  
  390. FW_SSuspendResumeState* FW_CGraphicDevice::Suspend()
  391. {
  392. // [KVV]    FW_ASSERT(!fSuspended);
  393.     FW_ASSERT(fOpenDeviceCount != 0);    // Should not have to Suspend if not opened
  394.  
  395. //    [KVV] When called from the drag manager, the current port has already been changed
  396. //    FW_CHECK_PLATFORM_CANVAS
  397.  
  398. #ifdef FW_BUILD_WIN
  399.     FW_SSuspendResumeState* deviceState = new FW_SSuspendResumeState();
  400.     deviceState->fSavedDC = ::SaveDC(fPlatformCanvas);
  401. #endif
  402. #ifdef FW_BUILD_MAC
  403.     FW_SSuspendResumeState* deviceState = GetState();
  404. #endif
  405.  
  406.     deviceState->fSavedContext = fContext;
  407.     fContext = NULL;
  408.  
  409.     fSuspended = TRUE;
  410.  
  411.     return deviceState;
  412. }
  413.  
  414. //---------------------------------------------------------------------------------------
  415. //    FW_CGraphicDevice::Resume
  416. //---------------------------------------------------------------------------------------
  417.  
  418. void FW_CGraphicDevice::Resume(FW_SSuspendResumeState* deviceState)
  419. {    
  420. // [KVV]    FW_ASSERT(fSuspended);
  421.     FW_ASSERT(fPlatformCanvas != NULL);
  422.     
  423.     FW_ASSERT(fContext == NULL);
  424.     fContext = deviceState->fSavedContext;
  425.  
  426. #ifdef FW_BUILD_WIN
  427.     ::RestoreDC(fPlatformCanvas, deviceState->fSavedDC);
  428. #endif
  429. #ifdef FW_BUILD_MAC
  430. //    [KVV] Drag and drop (also see comment in Suspend)
  431. //    FW_ASSERT(deviceState->fPreviousPlatformCanvas == fPlatformCanvas);
  432.  
  433.     ::SetPort(fPlatformCanvas);    // The port may have changed
  434.     
  435.     ::SetOrigin(deviceState->fOrigin.h, deviceState->fOrigin.v);
  436.     ::SetClip(deviceState->fClip);
  437.     ::DisposeRgn(deviceState->fClip);
  438.     deviceState->fClip = NULL;
  439.  
  440.     fSuspended = deviceState->fSuspended;        // [KVV] Resume should "fSuspended = FALSE"
  441.  
  442.     // ----- We need to reset our settings
  443.     ResetSettings();        
  444. #endif
  445.     
  446.     // ----- We don't need the suspendResumeState anymore -----
  447.     delete deviceState;
  448.     
  449.     // ----- We are not suspended anymore -----
  450.     fSuspended = FALSE;
  451. }
  452.  
  453. //---------------------------------------------------------------------------------------
  454. //    FW_CGraphicDevice::CanvasChanged
  455. //---------------------------------------------------------------------------------------
  456.  
  457. void FW_CGraphicDevice::CanvasChanged(Environment* ev, ODCanvas* newCanvas)
  458. {
  459.     FW_ASSERT(!fSuspended);
  460.     FW_ASSERT(fOpenDeviceCount == 0);
  461.     FW_ASSERT(fODCanvas != NULL);    // Should not change the canvas if didn't have a canvas already
  462.     
  463. #ifdef FW_BUILD_WIN
  464.     if(fPlatformCanvas != NULL)
  465.     {
  466.         fODCanvas->ReleasePlatformCanvas(ev);
  467.         fPlatformCanvas = NULL;
  468.     }
  469. #endif
  470.     
  471.     fODCanvas = newCanvas;
  472.     
  473. #ifdef FW_BUILD_WIN
  474.     fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODWindows);
  475. #endif
  476. #ifdef FW_BUILD_MAC
  477.     fPlatformCanvas = fODCanvas->GetPlatformCanvas(ev, kODQuickDraw);
  478. #endif
  479. }
  480.  
  481. //---------------------------------------------------------------------------------------
  482. //    FW_CGraphicDevice::MappingChanged
  483. //---------------------------------------------------------------------------------------
  484.  
  485. void FW_CGraphicDevice::MappingChanged()
  486. {
  487.     // ----- Set the origin offset -----
  488.     UpdateOriginForContext();
  489. }
  490.  
  491. //---------------------------------------------------------------------------------------
  492. //    FW_CGraphicDevice::UpdateOriginForContext
  493. //---------------------------------------------------------------------------------------
  494.  
  495. void FW_CGraphicDevice::UpdateOriginForContext()
  496. {
  497.     FW_SPlatformPoint offsetOrigin = fContext->GetOriginOffset();
  498.  
  499.     offsetOrigin.Set(
  500.         -offsetOrigin.X(),
  501.         -offsetOrigin.Y());
  502.  
  503.     SetOrigin(offsetOrigin);
  504. }
  505.  
  506. //---------------------------------------------------------------------------------------
  507. //    FW_CGraphicDevice::SetOrigin
  508. //---------------------------------------------------------------------------------------
  509.  
  510. void FW_CGraphicDevice::SetOrigin(FW_SPlatformPoint origin)
  511. {
  512.     FW_ASSERT(!fSuspended);
  513.     FW_ASSERT(fOpenDeviceCount != 0);
  514.  
  515.     FW_CHECK_PLATFORM_CANVAS
  516.  
  517. #ifdef FW_BUILD_WIN
  518.     ::SetWindowOrgEx(fPlatformCanvas, origin.x, origin.y, NULL);
  519. #endif
  520. #ifdef FW_BUILD_MAC
  521.     GrafPtr curPort;
  522.     ::GetPort(&curPort);
  523.  
  524.     FW_SPlatformPoint oldOrigin(curPort->portRect.left, curPort->portRect.top);
  525.     if(oldOrigin.h != origin.h || oldOrigin.v != origin.v)
  526.     {
  527.         // Set the port origin
  528.         ::SetOrigin(origin.h, origin.v);
  529.  
  530.         // Shift the clip region
  531.         ODRgnHandle rgn = GetClip();
  532.         ::OffsetRgn(rgn, origin.h - oldOrigin.h, origin.v - oldOrigin.v);
  533.         SetClip(rgn);
  534.         ::DisposeRgn(rgn);
  535.     }
  536. #endif
  537. }
  538.  
  539. //---------------------------------------------------------------------------------------
  540. //    FW_CGraphicDevice::SetClip
  541. //---------------------------------------------------------------------------------------
  542.  
  543. void FW_CGraphicDevice::SetClip(ODRgnHandle clipRegion)
  544. {
  545.     FW_ASSERT(!fSuspended);
  546.     FW_ASSERT(fOpenDeviceCount != 0);
  547.  
  548.     FW_CHECK_PLATFORM_CANVAS
  549.  
  550. #ifdef FW_BUILD_WIN
  551.     ::SelectClipRgn(fPlatformCanvas, clipRegion);
  552. #endif
  553. #ifdef FW_BUILD_MAC
  554.     if (fMacPostScriptClip)
  555.         MacEndPostScriptClip();
  556.     
  557.     if (FW_MacIsColorPort(FW_QDGlobals.thePort))    // [LW7]
  558.     {
  559.         ::SetClip(clipRegion);        // SetClip copies the region
  560.     }
  561.  
  562.     if (fODCanvas != NULL && fODCanvas->HasPlatformPrintJob(fEV, kODQuickDraw))
  563.     {
  564. #define bDevLaser            3    // copied from "PrPrivate.a"
  565.  
  566.         THPrint thPrint = (THPrint) fODCanvas->GetPlatformPrintJob(fEV, kODQuickDraw);
  567.         FW_Boolean bPostScript = (((**thPrint).prStl.wDev >> 8) == bDevLaser);
  568.         
  569.         if (bPostScript && (*clipRegion)->rgnSize != 10)
  570.         {
  571.             // If the region is not rectangular
  572.             MacBeginPostScriptClip(clipRegion);
  573.         }
  574.     }
  575. #endif
  576. }
  577.  
  578. //---------------------------------------------------------------------------------------
  579. //    FW_CGraphicDevice::GetClip
  580. //---------------------------------------------------------------------------------------
  581.  
  582. ODRgnHandle FW_CGraphicDevice::GetClip() const
  583. {
  584.     FW_ASSERT(!fSuspended);
  585.     FW_ASSERT(fOpenDeviceCount != 0);
  586.  
  587.     FW_CHECK_PLATFORM_CANVAS
  588.  
  589. #ifdef FW_BUILD_WIN
  590.     HRGN clipHandle = ::CreateRectRgn(0, 0, 0, 0);
  591.     ::GetClipRgn(fPlatformCanvas, clipHandle);
  592. #endif
  593. #ifdef FW_BUILD_MAC
  594.     ODRgnHandle clipHandle = ::NewRgn();
  595.     ::GetClip(clipHandle);
  596. #endif
  597.  
  598.     return clipHandle;
  599. }
  600.  
  601. //---------------------------------------------------------------------------------------
  602. //    FW_CGraphicDevice::SetClipRect
  603. //---------------------------------------------------------------------------------------
  604.  
  605. void FW_CGraphicDevice::SetClipRect(const FW_SPlatformRect& clipRect)
  606. {
  607.     FW_ASSERT(!fSuspended);
  608.     FW_ASSERT(fOpenDeviceCount != 0);
  609.  
  610.     FW_CHECK_PLATFORM_CANVAS
  611.  
  612. #ifdef FW_BUILD_WIN
  613.     ODRgnHandle clipRegion = ::CreateRectRgnIndirect(&clipRect);
  614.     ::SelectClipRgn(fPlatformCanvas, clipRegion);
  615.     ::DeleteObject(clipRegion);
  616. #endif
  617. #ifdef FW_BUILD_MAC
  618.     if (fMacPostScriptClip)
  619.         MacEndPostScriptClip();
  620.  
  621.     ::ClipRect(&clipRect);
  622. #endif
  623. }
  624.  
  625. //---------------------------------------------------------------------------------------
  626. //    FW_CGraphicDevice::IntersectClipRect
  627. //---------------------------------------------------------------------------------------
  628.  
  629. void FW_CGraphicDevice::IntersectClipRect(const FW_SPlatformRect& clipRect)
  630. {
  631.     FW_ASSERT(!fSuspended);
  632.     FW_ASSERT(fOpenDeviceCount != 0);
  633.  
  634.     FW_CHECK_PLATFORM_CANVAS
  635.  
  636. #ifdef FW_BUILD_WIN
  637.     ::IntersectClipRect(fPlatformCanvas,
  638.                         clipRect.left, clipRect.top, 
  639.                         clipRect.right, clipRect.bottom);
  640. #endif
  641. #ifdef FW_BUILD_MAC
  642.     if (fMacPostScriptClip)
  643.         MacEndPostScriptClip();
  644.  
  645.     ODRgnHandle rgn = ::NewRgn();
  646.     ::RectRgn(rgn, &clipRect);
  647.     ODRgnHandle curClip = GetClip();
  648.     ::SectRgn(curClip, rgn, curClip);
  649.     ::DisposeRgn(rgn);
  650.     SetClip(curClip);
  651.     ::DisposeRgn(curClip);
  652. #endif
  653. }
  654.  
  655. //---------------------------------------------------------------------------------------
  656. //    FW_CGraphicDevice::GetClipRect
  657. //---------------------------------------------------------------------------------------
  658.  
  659. void FW_CGraphicDevice::GetClipRect(FW_SPlatformRect& clipRect) const
  660. {
  661.     FW_ASSERT(!fSuspended);
  662.     FW_ASSERT(fOpenDeviceCount != 0);
  663.  
  664.     FW_CHECK_PLATFORM_CANVAS
  665.  
  666. #ifdef FW_BUILD_WIN
  667.     ::GetClipBox(fPlatformCanvas, &clipRect);
  668. #endif
  669. #ifdef FW_BUILD_MAC
  670.     clipRect = (*FW_QDGlobals.thePort->clipRgn)->rgnBBox;
  671. #endif
  672. }
  673.  
  674. #ifdef FW_BUILD_MAC
  675. //----------------------------------------------------------------------------------------
  676. //    FW_CGraphicDevice::SetHiliteMode
  677. //----------------------------------------------------------------------------------------
  678.  
  679. void FW_CGraphicDevice::SetHiliteMode()
  680. {
  681.     unsigned char HiliteModeValue = LMGetHiliteMode();
  682.     ::BitClr(&HiliteModeValue, pHiliteBit);
  683.     LMSetHiliteMode(HiliteModeValue);
  684. }
  685. #endif
  686.  
  687. #ifdef FW_BUILD_MAC
  688. //----------------------------------------------------------------------------------------
  689. //    FW_CGraphicDevice::SetInGrafPort
  690. //----------------------------------------------------------------------------------------
  691. //    [HLX] Maybe it is as fast to just set than testing and setting???
  692.  
  693. void FW_CGraphicDevice::SetInGrafPort()
  694. {
  695.     FW_ASSERT(!fSuspended);
  696.     FW_ASSERT((fOpenDeviceCount != 0) && (fPlatformCanvas == FW_QDGlobals.thePort));
  697.     
  698.     if (fChangeFlag & FW_kForeColorChanged)
  699.         ::RGBForeColor(&fForeColor);
  700.         
  701.     if (fChangeFlag & FW_kBackColorChanged)
  702.         ::RGBBackColor(&fBackColor);
  703.         
  704.     if (fChangeFlag & FW_kHiliteColorChanged)
  705.         ::HiliteColor(&fHiliteColor);
  706.         
  707.     if (fChangeFlag & FW_kPatternChanged)
  708.         fPattern->MacSetInCurPort();
  709.         
  710.     if (fPlatformCanvas->pnSize.h != fHPenSize || fPlatformCanvas->pnSize.v != fVPenSize)
  711.         ::PenSize(fHPenSize, fVPenSize);
  712.         
  713.     if (fPlatformCanvas->txFont != fFontID)
  714.         ::TextFont(fFontID);
  715.         
  716.     if (fPlatformCanvas->txSize != fFontSize)
  717.         ::TextSize(fFontSize);
  718.         
  719.     if (fPlatformCanvas->txFace != fFontStyle)
  720.         ::TextFace(fFontStyle);
  721.         
  722.     if (fPlatformCanvas->pnMode != fPenMode)
  723.         ::PenMode(fPenMode);
  724.         
  725.     if (fPlatformCanvas->txMode != fTextMode)
  726.         ::TextMode(fTextMode);
  727.     
  728.     fChangeFlag = 0;
  729. }
  730. #endif
  731.  
  732. #ifdef FW_BUILD_MAC
  733. //----------------------------------------------------------------------------------------
  734. //    FW_CGraphicDevice::ResetSettings
  735. //----------------------------------------------------------------------------------------
  736.  
  737. void FW_CGraphicDevice::ResetSettings()
  738. {
  739.     FW_ASSERT((fPlatformCanvas == FW_QDGlobals.thePort));
  740.  
  741.     ::GetForeColor(&fForeColor);
  742.     ::GetBackColor(&fBackColor);
  743.     
  744.     LMGetHiliteRGB(&fHiliteColor);        // [HLX] I am not sure about that
  745.     ::HiliteColor(&fHiliteColor);
  746.     
  747.     fPattern = FW_kBlackPat;
  748.     fPattern->MacSetInCurPort();
  749.     
  750.     fHPenSize = fPlatformCanvas->pnSize.h;
  751.     fVPenSize = fPlatformCanvas->pnSize.v;
  752.     fFontID = fPlatformCanvas->txFont;
  753.     fFontSize = fPlatformCanvas->txSize;
  754.     fFontStyle = fPlatformCanvas->txFace;
  755.     fPenMode = fPlatformCanvas->pnMode;
  756.     fTextMode = fPlatformCanvas->txMode;
  757.     
  758.     fChangeFlag = 0;
  759. }
  760. #endif
  761.  
  762. #ifdef FW_BUILD_MAC
  763. //----------------------------------------------------------------------------------------
  764. //    GetMacTransferMode
  765. //----------------------------------------------------------------------------------------
  766.  
  767. static short GetMacTransferMode(FW_TransferModes transferMode)
  768. {
  769.     if ((transferMode & 0xFFFF0000) == 0)
  770.         return (short)transferMode;        // Native transfer mode
  771.     else
  772.     {
  773.         FW_ASSERT(transferMode <= FW_LastTransferMode);
  774.         return FW_gTransferModes[transferMode & 0x0000FFFF];
  775.     }
  776. }
  777. #endif
  778.  
  779. #ifdef FW_BUILD_MAC
  780. //----------------------------------------------------------------------------------------
  781. //    FW_CGraphicDevice::SelectInk
  782. //----------------------------------------------------------------------------------------
  783.  
  784. void FW_CGraphicDevice::SelectInk(const FW_PInk& ink, 
  785.                                 FW_EShapeCategories shapeCategory, 
  786.                                 FW_ERenderVerbs renderVerb)
  787. {
  788.     FW_ASSERT((const void*)ink != NULL);
  789.  
  790.     FW_CColor foreColor, backColor;
  791.     FW_TransferModes transferMode = ink->GetTransferMode();
  792.     
  793.     ink->GetForeColor(foreColor);
  794.     ink->GetBackColor(backColor);
  795.     
  796.     if (transferMode == FW_kHilite)
  797.         SetHiliteColor(foreColor);
  798.  
  799.     switch (shapeCategory)
  800.     {
  801.         case FW_kLineShape:
  802.             if (transferMode == FW_kErase)
  803.             {
  804.                 SetForeColor(backColor);
  805.                 SetBackColor(backColor);
  806.                 SetPenMode(GetMacTransferMode(transferMode));
  807.             }
  808.             else if (transferMode == FW_kInvert)
  809.             {
  810.                 SetForeColor(foreColor);
  811.                 SetBackColor(backColor);
  812.                 SetPenMode(patXor);
  813.             }
  814.             else
  815.             {
  816.                 SetForeColor(foreColor);
  817.                 SetBackColor(backColor);
  818.                 SetPenMode(GetMacTransferMode(transferMode));
  819.             }
  820.             break;
  821.             
  822.         case FW_kGeometricShape:
  823.             if (renderVerb == FW_kFrame)
  824.             {
  825.                 if (transferMode == FW_kErase)
  826.                 {
  827.                     SetForeColor(backColor);
  828.                     SetBackColor(backColor);
  829.                     SetPenMode(patCopy);
  830.                 }
  831.                 else if (transferMode == FW_kInvert)
  832.                 {
  833.                     SetForeColor(foreColor);
  834.                     SetBackColor(backColor);
  835.                     SetPenMode(patXor);
  836.                 }
  837.                 else
  838.                 {
  839.                     SetForeColor(foreColor);
  840.                     SetBackColor(backColor);
  841.                     SetPenMode(GetMacTransferMode(transferMode));
  842.                 }
  843.                 break;
  844.             }
  845.             else
  846.             {
  847.                 SetForeColor(foreColor);
  848.                 SetBackColor(backColor);
  849.                 if (transferMode == FW_kInvert || transferMode == FW_kErase)
  850.                     SetPenMode(patCopy);    // I will use ::InvertXXX or ::EraseXXX
  851.                 else
  852.                     SetPenMode(GetMacTransferMode(transferMode));
  853.             }
  854.             
  855.             break;
  856.             
  857.         case FW_kTypographicShape:
  858.             SetBackColor(backColor);
  859.             if (transferMode == FW_kInvert)
  860.             {
  861.                 SetForeColor(foreColor);
  862.                 SetPenMode(patXor);
  863.             }
  864.             else if (transferMode == FW_kErase)
  865.             {
  866.                 SetForeColor(backColor);
  867.                 SetPenMode(patCopy);
  868.             }
  869.             else
  870.             {
  871.                 SetForeColor(foreColor);
  872.                 SetTextMode(GetMacTransferMode(transferMode));
  873.             }
  874.             break;
  875.         
  876.         case FW_kImageShape:
  877.             SetForeColor(foreColor);
  878.             SetBackColor(backColor);
  879.             SetPenMode(GetMacTransferMode(transferMode));
  880.             break;
  881.     }
  882. }
  883. #endif
  884.  
  885. #ifdef FW_BUILD_MAC
  886. //----------------------------------------------------------------------------------------
  887. //    FW_CGraphicDevice::SelectStyle
  888. //----------------------------------------------------------------------------------------
  889.  
  890. FW_Boolean FW_CGraphicDevice::SelectStyle(const FW_PStyle& style, 
  891.                                     FW_TransferModes transferMode)
  892. {
  893.     FW_ASSERT((const void*)style != NULL);
  894.  
  895.     if (transferMode == FW_kInvert || transferMode == FW_kErase)
  896.         SetPattern(FW_kBlackPat);
  897.     else
  898.         SetPattern(style->GetPattern());
  899.  
  900.     FW_EStyleDash dash = style->GetDashStyle();
  901.     FW_CFixed penSize = style->GetPenSize();
  902.     
  903.     FW_SPlatformPoint plfmPt;
  904.     if (!penSize)
  905.     {
  906.         plfmPt.Set(1, 1);
  907.     }
  908.     else
  909.     {
  910.         plfmPt = fContext->LogicalToDevice(penSize, penSize);
  911.         
  912.         if (plfmPt.h == 0)
  913.             plfmPt.h = 1;
  914.             
  915.         if (plfmPt.v == 0)
  916.             plfmPt.v = 1;
  917.     }
  918.  
  919.     SetPenSize(plfmPt.h, plfmPt.v);
  920.     
  921.     return dash != FW_kSolidLine && plfmPt.h <= 1 && plfmPt.v <= 1;
  922. }
  923. #endif
  924.  
  925. #ifdef FW_BUILD_MAC
  926. //----------------------------------------------------------------------------------------
  927. //    FW_CGraphicDevice::SetPattern
  928. //----------------------------------------------------------------------------------------
  929.  
  930. void FW_CGraphicDevice::SetPattern(const FW_PPattern& pattern)
  931. {
  932.     fPattern =    pattern;
  933.     fChangeFlag |= FW_kPatternChanged;
  934. }
  935. #endif
  936.  
  937. #ifdef FW_BUILD_MAC
  938.  
  939. #define kPostScriptBegin    190        // Picture-comments for PostScript printing
  940. #define kPostScriptEnd        191
  941. #define kTextIsPostScript    194
  942.  
  943. //----------------------------------------------------------------------------------------
  944. //    FW_CGraphicDevice::MacBeginPostScriptClip
  945. //----------------------------------------------------------------------------------------
  946.  
  947. void FW_CGraphicDevice::MacBeginPostScriptClip(RgnHandle rgn)
  948. {
  949.     FW_ASSERT(!fMacPostScriptClip);
  950.  
  951.     //    In order for the PostScript commands we'll be emitting below to sync up
  952.     //    properly with other PS code the driver emits, we have to get something else
  953.     //    to emit right now as a flush. So we'll draw a tiny rectangle and make sure
  954.     //    it falls outside the clipping bounds.
  955.     
  956.     Rect bbox = (*rgn)->rgnBBox;
  957.  
  958.     Rect r;
  959.     r.right = bbox.left;
  960.     if (r.right == -32767)
  961.         r.right = bbox.right + 1;
  962.     r.bottom = bbox.top;
  963.     if (r.bottom == -32767)
  964.         r.bottom = bbox.bottom + 1;
  965.     r.left = r.right - 1;
  966.     r.top  = r.bottom - 1;
  967.     ::PaintRect(&r);
  968.  
  969.     // Copy a region to a shape so it can be converted to a polygon
  970.     RgnHandle rgnCopy = ::NewRgn();
  971.     ::CopyRgn(rgn, rgnCopy);
  972.     ODShape* shape = FW_NewODShape(fEV, rgnCopy);
  973.  
  974.     // Now emit the polygon as a PostScript path and clip to it
  975.     ODPolygon poly;
  976.     shape->CopyPolygon(fEV, &poly);
  977.     
  978.     FW_ODPolygonData* polyData = (FW_ODPolygonData*) poly._buffer;
  979.  
  980.     ::PicComment(kPostScriptBegin, 0, kODNULL);
  981.     ::PicComment(kTextIsPostScript, 0, kODNULL);
  982.  
  983.     ::DrawString("\ppse gsave");            // Cancels out the 'psb' generated by the LW driver
  984.     ::DrawString("\pnewpath");
  985.  
  986.     char buf[128];
  987.     FW_ODContour* cont = polyData->fContours;
  988.     for (long n = polyData->fContourCount; n > 0; -- n, cont = cont->NextContour())
  989.     {
  990.         const FW_CPoint* v = cont->fVertex;
  991.         long m = cont->fVertexCount;
  992.         if (m > 2)
  993.         {
  994.             ::DrawText(buf, 0,
  995.                 sprintf(buf, "%.2f %.2f moveto", v->x.AsDouble(), v->y.AsDouble()));
  996.  
  997.             while (--m > 0)
  998.             {
  999.                 ++ v;
  1000.                 ::DrawText(buf, 0,
  1001.                     sprintf(buf,"%.2f %.2f lineto", v->x.AsDouble(), v->y.AsDouble()));
  1002.             }
  1003.         }
  1004.     }
  1005.  
  1006.     ::DrawString("\pclosepath clip");    // Adding newpath would be nice but LW7 no likee
  1007.  
  1008.     ::DrawString("\ppsb");                // Cancels out the forthcoming 'pse'
  1009.     ::PicComment(kPostScriptEnd, 0,kODNULL);
  1010.  
  1011.     delete[] poly._buffer;
  1012.     
  1013.     shape->Release(fEV);
  1014.  
  1015.     fMacPostScriptClip = TRUE;
  1016. }
  1017. #endif
  1018.  
  1019. #ifdef FW_BUILD_MAC
  1020. //----------------------------------------------------------------------------------------
  1021. //    FW_CGraphicDevice::MacEndPostScriptClip
  1022. //----------------------------------------------------------------------------------------
  1023.  
  1024. void FW_CGraphicDevice::MacEndPostScriptClip()
  1025. {
  1026.     FW_ASSERT(fMacPostScriptClip);
  1027.  
  1028.     PicComment(kPostScriptBegin, 0,kODNULL);
  1029.     PicComment(kTextIsPostScript, 0,kODNULL);
  1030.     DrawString("\ppse currentpoint grestore moveto psb");
  1031.     PicComment(kPostScriptEnd, 0,kODNULL);
  1032.  
  1033.     fMacPostScriptClip = FALSE;
  1034. }
  1035. #endif
  1036.  
  1037. //----------------------------------------------------------------------------------------
  1038. //    FW_CGraphicDevice::SelectFont
  1039. //----------------------------------------------------------------------------------------
  1040.  
  1041. void FW_CGraphicDevice::SelectFont(const FW_PFont& font, FW_Boolean scale)
  1042. {
  1043.     FW_ASSERT(!fSuspended);
  1044.     FW_ASSERT(fOpenDeviceCount != 0);
  1045.     
  1046.     FW_CHECK_PLATFORM_CANVAS
  1047.  
  1048.     FW_ASSERT((const void*)font != NULL);
  1049.  
  1050. #ifdef FW_BUILD_WIN
  1051.     FW_CString255 fontName;
  1052.     font->GetFontName(fontName);
  1053.     fGDIFont.SetFontName(fontName);
  1054.     fGDIFont.SetFontStyle(font->GetFontStyle());
  1055. #endif
  1056. #ifdef FW_BUILD_MAC
  1057.     SetFontID(font->MacGetFontID());
  1058.     SetFontStyle(font->MacGetFontStyle());
  1059. #endif
  1060.     
  1061.     FW_CFixed fontSize = font->GetFontSize();
  1062.     if (scale)
  1063.     {
  1064.         FW_SPlatformPoint pt = fContext->LogicalToDevice(fontSize, fontSize);
  1065.         fontSize.SetInt(pt.Y());
  1066.     }
  1067.  
  1068. #ifdef FW_BUILD_WIN
  1069.     fGDIFont.SetFontSize(fontSize.AsInt());
  1070.     fGDIFont.SelectObject(fPlatformCanvas);
  1071. #endif        
  1072. #ifdef FW_BUILD_MAC
  1073.     SetFontSize(fontSize.AsInt());
  1074.     SetInGrafPort();
  1075. #endif
  1076. }
  1077.  
  1078. #ifdef FW_BUILD_WIN
  1079. //----------------------------------------------------------------------------------------
  1080. //    FW_CGraphicDevice::SelectInkAndFont
  1081. //----------------------------------------------------------------------------------------
  1082. //    Only call for Text shapes
  1083.  
  1084. void FW_CGraphicDevice::SelectInkAndFont(const FW_PInk& ink, const FW_PFont& font)
  1085. {
  1086.     SetTextColor(*ink->GetForeColor());
  1087.     SetBkColor(*ink->GetBackColor());
  1088.     SetBkMode(ink->GetTransferMode() == FW_kOr ? TRANSPARENT : OPAQUE);
  1089.     
  1090.     SelectFont(font, TRUE);
  1091. }
  1092. #endif
  1093.  
  1094. #ifdef FW_BUILD_WIN
  1095. //----------------------------------------------------------------------------------------
  1096. //    FW_CGraphicDevice::SetTextColor
  1097. //----------------------------------------------------------------------------------------
  1098.  
  1099. void FW_CGraphicDevice::SetTextColor(COLORREF textColor)
  1100. {
  1101.     FW_ASSERT(!fSuspended);
  1102.     FW_ASSERT(fOpenDeviceCount != 0);
  1103.     
  1104.     FW_CHECK_PLATFORM_CANVAS
  1105.  
  1106.     if (fTextColor != textColor)
  1107.     {
  1108.         fTextColor = textColor;
  1109.         ::SetTextColor(fPlatformCanvas, textColor);
  1110.     }
  1111. }
  1112. #endif
  1113.  
  1114. #ifdef FW_BUILD_WIN
  1115. //----------------------------------------------------------------------------------------
  1116. //    FW_CGraphicDevice::SetBkColor
  1117. //----------------------------------------------------------------------------------------
  1118.  
  1119. void FW_CGraphicDevice::SetBkColor(COLORREF bkColor)
  1120. {
  1121.     FW_ASSERT(!fSuspended);
  1122.     FW_ASSERT(fOpenDeviceCount != 0);
  1123.     
  1124.     FW_CHECK_PLATFORM_CANVAS
  1125.  
  1126.     if (fBkColor != bkColor)
  1127.     {
  1128.         fBkColor = bkColor;
  1129.         ::SetBkColor(fPlatformCanvas, bkColor);
  1130.     }
  1131. }
  1132. #endif
  1133.  
  1134. #ifdef FW_BUILD_WIN
  1135. //----------------------------------------------------------------------------------------
  1136. //    PrivWinROP2
  1137. //----------------------------------------------------------------------------------------
  1138.  
  1139. int static PrivWinROP2(FW_TransferModes transferMode)
  1140. {
  1141.     if ((transferMode & 0xFFFF0000L) == 0)
  1142.         return (int)transferMode;        // Native transfer mode
  1143.     else
  1144.     {
  1145.         FW_ASSERT(transferMode <= FW_LastTransferMode);
  1146.         return FW_gTransferModes[transferMode & 0x0000FFFFL];
  1147.     }
  1148. }
  1149. #endif
  1150.  
  1151. #ifdef FW_BUILD_WIN
  1152. //----------------------------------------------------------------------------------------
  1153. //    FW_CGraphicDevice::SelectInkAndStyle
  1154. //----------------------------------------------------------------------------------------
  1155. // Only call for shapeCategory == FW_kGeometricShape or FW_kGeometricShapeWithInvert
  1156.  
  1157. FW_Boolean FW_CGraphicDevice::SelectInkAndStyle(const FW_PInk& ink, 
  1158.                                                    const FW_PStyle& style,
  1159.                                                    FW_EShapeCategories shapeCategory, 
  1160.                                                    FW_ERenderVerbs renderVerb)
  1161. {
  1162.     FW_ASSERT(!fSuspended);
  1163.     FW_ASSERT(fOpenDeviceCount != 0);
  1164.     
  1165.     FW_CHECK_PLATFORM_CANVAS
  1166.  
  1167.     FW_ASSERT((const void*)ink != NULL);
  1168.     FW_ASSERT((const void*)style != NULL);
  1169.     
  1170.     FW_Boolean frameWithBrush = FALSE;
  1171.     
  1172.     // ----- Set transfer mode -----
  1173.     if (shapeCategory == FW_kGeometricShapeWithInvert && 
  1174.         ink->GetTransferMode() == FW_kInvert || 
  1175.         ink->GetTransferMode() == FW_kHilite)
  1176.     {
  1177.         SetDrawingMode(R2_COPYPEN);
  1178.     }
  1179.     else
  1180.         SetDrawingMode(::PrivWinROP2(ink->GetTransferMode()));
  1181.  
  1182.     // ----- Set pen size (even if filling)    
  1183.     FW_CFixed penSize = style->GetPenSize();
  1184.     if (!penSize)
  1185.         fPenSize.Set(1,1);
  1186.     else
  1187.         fPenSize = fContext->LogicalToDevice(penSize, penSize);
  1188.  
  1189.     // ----- Set pen and brush -----
  1190.     int nBkMode = OPAQUE;
  1191.     if (renderVerb == FW_kFrame)
  1192.     {
  1193.         FW_EStyleDash dash = style->GetDashStyle();
  1194.         frameWithBrush = (dash == FW_kSolidLine) && (!ink->PrivSpecialTransferMode()) && (!style->GetPattern()->IsBlack());
  1195.         
  1196.         if (frameWithBrush)
  1197.         {
  1198.             // NOTE: I don't set the Pen because we will not use it
  1199.             
  1200.             // ----- Set foreground and background Color -----
  1201.             SetTextColor(*ink->GetForeColor());
  1202.             SetBkColor(*ink->GetBackColor());
  1203.     
  1204.             // ----- Set Brush -----
  1205.             fGDIBrush.SetBrushPattern(style->GetPattern());
  1206.         }
  1207.         else
  1208.         {
  1209.             // ----- Set the Brush -----
  1210.             fGDIBrush.SetStockID(NULL_BRUSH);
  1211.  
  1212.             // ----- Set the pen -----
  1213.             fGDIPen.SetPenSize(fPenSize.y);
  1214.             fGDIPen.SetPenStyle(dash);
  1215.             fGDIPen.SetPenColor(ink->GetTransferMode() == FW_kErase ? *ink->GetBackColor() : *ink->GetForeColor());
  1216.             
  1217.             if ((dash & FW_kOpaque) == 0)
  1218.                 nBkMode = TRANSPARENT;
  1219.             else
  1220.                 SetBkColor(*ink->GetBackColor());
  1221.         }
  1222.     }
  1223.     else
  1224.     {
  1225.         // ----- Set the pen -----
  1226.         fGDIPen.SetStockID(NULL_PEN);
  1227.  
  1228.         // ----- Set the Brush -----
  1229.         FW_TransferModes transferMode = ink->GetTransferMode();
  1230.         if (transferMode == FW_kErase)
  1231.         {
  1232.             SetTextColor(FW_kRGBBlack);
  1233.             SetBkColor(FW_kRGBWhite);
  1234.             fGDIBrush.SetBrushColor(*ink->GetBackColor());
  1235.         }
  1236.         else if (transferMode == FW_kInvert || transferMode == FW_kHilite)
  1237.         {
  1238.             SetTextColor(FW_kRGBBlack);
  1239.             SetBkColor(FW_kRGBWhite);
  1240.             fGDIBrush.SetStockID(BLACK_BRUSH);
  1241.         }
  1242.         else
  1243.         {
  1244.             const FW_PPattern& pattern = style->GetPattern();
  1245.  
  1246.             if (pattern->IsBlack())
  1247.             {
  1248.                 // If pattern is black let just use a solid brush
  1249.                 SetTextColor(FW_kRGBBlack);
  1250.                 SetBkColor(FW_kRGBWhite);
  1251.                 fGDIBrush.SetBrushColor(*ink->GetForeColor());
  1252.             }
  1253.             else
  1254.             {
  1255.                 SetTextColor(*ink->GetForeColor());
  1256.                 SetBkColor(*ink->GetBackColor());
  1257.                 fGDIBrush.SetBrushPattern(pattern);
  1258.             }
  1259.         }
  1260.     }
  1261.     
  1262.     SetBkMode(nBkMode);
  1263.  
  1264.     if (!frameWithBrush)
  1265.     {
  1266.         fGDIPen.SelectObject(fPlatformCanvas);
  1267.         fGDIBrush.SelectObject(fPlatformCanvas);
  1268.     }
  1269.  
  1270.     return frameWithBrush;
  1271. }
  1272. #endif
  1273.